package application;

public class Ligne {
	private int y = 0;
	private int taille = 0;
	/**
	 * @return the y
	 */
	public int getY() {
		return y;
	}

	/**
	 * @return the taille
	 */
	public int getTaille() {
		return taille;
	}

	/**
	 * @return the debut
	 */
	public int getDebut() {
		return debut;
	}

	/**
	 * @return the fin
	 */
	public int getFin() {
		return fin;
	}

	/**
	 * @return the horizontale
	 */
	public boolean isHorizontale() {
		return horizontale;
	}

	private int debut =0;
	private int fin =0;
	private boolean horizontale = true;

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Ligne [y=" + y + ", debut=" + debut + ", fin=" + fin + "]";
	}

	public Ligne(int i, int xDebut, int xFin) {
		this.y=i;
		this.debut=xDebut;
		this.fin=xFin;
		this.taille=xFin-xDebut;
	}
	
	public Ligne(int i, int xDebut, int xFin, boolean horizontale) {
		this.y=i;
		this.debut=xDebut;
		this.fin=xFin;
		this.horizontale=horizontale;
	}
	
	public Ligne fusionLigne(Ligne l1, Ligne l2)
	{
		if(l1.debut < l2.debut)
			if(l1.fin > l2.fin)
				return new Ligne(l1.y,l1.debut,l1.fin);
			else
				return new Ligne(l1.y,l1.debut,l2.fin);
		else
			if(l1.fin > l2.fin)
				return new Ligne(l1.y,l2.debut,l1.fin);
			else
				return new Ligne(l1.y,l2.debut,l2.fin);
	}
}
